<?php
// $Id$

include_once('BaseModel.class.php');

class ManageModulesModel extends BaseModel
{
    function collect($offset=null,$limit=null,$search=array(),$by='1',$sort='')
	{
		$where = ($search) ? "WHERE LOWER({$search['searchfield']}) LIKE '%{$search['searchtext']}%'" : "WHERE 1";

		if (is_null($offset)) {
	        $query = "SELECT COUNT(*) FROM user_modules $where";
		} else {
	        $query = "SELECT um.modules_id,um.module_name,um.description,
                          umg.modulegroup_name as modulegroup,um.created_by,um.creation_date,
                          ut.usertype_name as type
                           FROM user_modules um
                          JOIN user_modulegroups umg ON um.modulegroup_id = umg.id
                          LEFT JOIN usertype ut ON um.usertype_id = ut.id
                           $where ORDER BY $by $sort LIMIT $offset,$limit";
		}
		return $this->query($query, true);
   } 
    function detail ($id){

        $query = "SELECT * FROM user_modules WHERE modules_id='$id'";
        return $this->query($query, true);
    }

    /*
     * Add categories and return the new categories_id
     *
     */
    function ins($detail)
    {
        return $this->insert('user_modules', $detail);
        return $this->last_insert_id('user_modules');
    }

    /*
     * Update categories for a particular categories_id
     *
     */
    function edit ($id, $detail)
    {
        return $this->update('user_modules', $detail, "modules_id = '$id'");
    }

    /*
     * Delete categories detail for a particular categories_id
     *
     */
    function deactivate ($id)
    {
        $query = "UPDATE user_modules SET active = '0' WHERE id='$id'";
        return $this->query($query, false);
    }
    function activate ($id)
    {
        $query = "UPDATE user_modules SET active = '1' WHERE id='$id'";
        return $this->query($query, false);
    }
}

?>
